package c.x.jy.wexin.controller;


 
import c.x.jy.common.annotation.IntoSet;
import c.x.jy.common.annotation.Login;
import c.x.jy.common.utils.PageUtils;
import c.x.jy.common.utils.R;
import c.x.jy.dao.dto.TeacherEntityDto;
import c.x.jy.dao.entity.MemberEntity;
import c.x.jy.dao.entity.TeacherEntity;
import c.x.jy.service.service.MemberService;
import c.x.jy.service.service.TeacherService;
import c.x.jy.service.service.TeacherServiceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;



/**
 * 老师申请及信息表
 *
 * @author amwhyh
 * @email xxx@xx.com
 * @date 2021-05-24 10:16:30
 */
@RestController
@RequestMapping("wechat/teacher")
public class TeacherController  {

    @Autowired
    private MemberService customerService;
    @Autowired
    private TeacherService teacherService;
    @Autowired
    private   TeacherServiceService teacherServiceService;
    @Autowired
    private MemberService memberService;
    /**
     * 列表
     */
     @Login
    @IntoSet(Includefields={"teacherServiceService","online"})
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        params.put("businessId",customerService.getCurrUser().getBusinessId());
        PageUtils page = teacherService.queryPage(params);

        return R.put(page);
    }

    @Login
    @IntoSet(Includefields={"teacherServiceService","online","minprice"})
    @RequestMapping("/all")
    public R all(@RequestParam Map<String, Object> params){
        PageUtils page = teacherService.selectlist(params);

        return R.put(page);
    }
     @Login
    @RequestMapping("/serversbyMemberId")
    public R selectServiceBymemberId( Long memberId){
 
        return R.put(teacherServiceService.selectServiceBymemberId(memberId));
    }

     @Login
    @RequestMapping("/serversByTearchId")
    public R selectServiceByTeacherId( Long tearcherId){
 
        return R.put(teacherServiceService.selectServiceByTeacherId(tearcherId));
    }
    //根据服务项目编号获取专家列表
    @IntoSet(Includefields={"online","minprice"})
    @Login
    @RequestMapping("/selectTeacherInfoByServiceId")
    public R selectTeacherInfoByServiceId( Long serviceId,Integer orderBy,String servicename){

        return R.put(teacherService.selectTeacherInfoByServiceId(serviceId,orderBy,servicename));
    }
    /**
     * 信息
     */
     @Login
    @IntoSet(Includefields={"membername","membernickName","teacherServiceService","headimgurl","country","province","city"})
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
//		TeacherEntity teacher = teacherService.getById(id);
         TeacherEntityDto teacher = teacherService.selectById(id);
       // TeacherEntityDto dto=new TeacherEntityDto();
      //  GetClassinfo.ObjectChangeToObject(teacher,dto );
        return R.put(teacher);
    }
    //根据当前用户的MemberID，获取大师资格申请的记录
    @RequestMapping("/getByMemberId")
    @Login
    public R getByMemberId(){
        return R.put(teacherService.getByMemberId(memberService.getCurrUser().getId()));
    }
    /**
     * 保存
     */
    
    @RequestMapping("/save")
    @Login
    public R save(@RequestBody TeacherEntity teacher){
        MemberEntity currentUser = memberService.getCurrUser();
        teacher.setBusinessId(currentUser.getBusinessId());
        teacher.setMemberId(currentUser.getId());
        teacher.setStatus(1);
		teacherService.save(teacher);

        return R.ok();
    }
    //获得明星大师
    @RequestMapping("/hotTeacher")
    public R hotTeachers(){

        List<TeacherEntityDto> list = teacherService.hotTeachers();

        return R.put(list);
    }
    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody TeacherEntity teacher){
		teacherService.updateById(teacher);

        return R.ok();
    }
    
   

    /**
     * 删除
     */
    @RequestMapping("/delete/{id}")
    public R delete(@PathVariable("id") Long id){
		teacherService.removeByIds(Arrays.asList(id));

        return R.ok();
    }

}

